home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / LFOSpecifier.c < prev    next >
Text File  |  1994-12-10  |  6KB  |  219 lines

  1. /* LFOSpecifier.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "LFOSpecifier.h"
  31. #include "Memory.h"
  32. #include "Envelope.h"
  33. #include "SampleSelector.h"
  34.  
  35.  
  36. struct LFOSpecRec
  37.     {
  38.         /* envelope that determines the frequency of the LFO oscillator */
  39.         EnvelopeRec*                    FrequencyEnvelope;
  40.  
  41.         /* envelope that determines the amplitude of the LFO wave */
  42.         EnvelopeRec*                    AmplitudeEnvelope;
  43.  
  44.         /* envelope that determines wave table index -- wave table LFOs only */
  45.         EnvelopeRec*                    WaveTableIndexEnvelope;
  46.  
  47.         /* sample / wave table sources */
  48.         SampleSelectorRec*        SampleSources;
  49.  
  50.         /* what kind of wave generator should we use */
  51.         LFOOscTypes                        Oscillator;
  52.  
  53.         /* how should the LFO wave affect the stream being modulated */
  54.         LFOModulationTypes        ModulationMode;
  55.  
  56.         /* how are the signals combined */
  57.         LFOAdderMode                    AddingMode;
  58.  
  59.         /* extra value */
  60.         double                                ExtraValue;
  61.     };
  62.  
  63.  
  64. /* create a new LFO specification record */
  65. LFOSpecRec*                        NewLFOSpecifier(void)
  66.     {
  67.         LFOSpecRec*                    LFOSpec;
  68.  
  69.         LFOSpec = (LFOSpecRec*)AllocPtrCanFail(sizeof(LFOSpecRec),"LFOSpecRec");
  70.         if (LFOSpec == NIL)
  71.             {
  72.              FailurePoint1:
  73.                 return NIL;
  74.             }
  75.         LFOSpec->FrequencyEnvelope = NewEnvelope();
  76.         if (LFOSpec->FrequencyEnvelope == NIL)
  77.             {
  78.              FailurePoint2:
  79.                 ReleasePtr((char*)LFOSpec);
  80.                 goto FailurePoint1;
  81.             }
  82.         LFOSpec->AmplitudeEnvelope = NewEnvelope();
  83.         if (LFOSpec->AmplitudeEnvelope == NIL)
  84.             {
  85.              FailurePoint3:
  86.                 DisposeEnvelope(LFOSpec->FrequencyEnvelope);
  87.                 goto FailurePoint2;
  88.             }
  89.         LFOSpec->WaveTableIndexEnvelope = NewEnvelope();
  90.         if (LFOSpec->WaveTableIndexEnvelope == NIL)
  91.             {
  92.              FailurePoint4:
  93.                 DisposeEnvelope(LFOSpec->AmplitudeEnvelope);
  94.                 goto FailurePoint3;
  95.             }
  96.         LFOSpec->SampleSources = NewSampleSelectorList(0);
  97.         if (LFOSpec->SampleSources == NIL)
  98.             {
  99.              FailurePoint5:
  100.                 DisposeEnvelope(LFOSpec->WaveTableIndexEnvelope);
  101.                 goto FailurePoint4;
  102.             }
  103.         LFOSpec->Oscillator = eLFOSignedSine;
  104.         LFOSpec->ModulationMode = eLFOAdditive;
  105.         LFOSpec->AddingMode = eLFOArithmetic;
  106.         LFOSpec->ExtraValue = 1;
  107.         return LFOSpec;
  108.     }
  109.  
  110.  
  111. /* dispose an LFO specification */
  112. void                                    DisposeLFOSpecifier(LFOSpecRec* LFOSpec)
  113.     {
  114.         CheckPtrExistence(LFOSpec);
  115.         DisposeSampleSelectorList(LFOSpec->SampleSources);
  116.         DisposeEnvelope(LFOSpec->WaveTableIndexEnvelope);
  117.         DisposeEnvelope(LFOSpec->FrequencyEnvelope);
  118.         DisposeEnvelope(LFOSpec->AmplitudeEnvelope);
  119.         ReleasePtr((char*)LFOSpec);
  120.     }
  121.  
  122.  
  123. /* get the frequency envelope record */
  124. EnvelopeRec*                    GetLFOSpecFrequencyEnvelope(LFOSpecRec* LFOSpec)
  125.     {
  126.         CheckPtrExistence(LFOSpec);
  127.         return LFOSpec->FrequencyEnvelope;
  128.     }
  129.  
  130.  
  131. /* get the amplitude envelope record */
  132. struct EnvelopeRec*        GetLFOSpecAmplitudeEnvelope(LFOSpecRec* LFOSpec)
  133.     {
  134.         CheckPtrExistence(LFOSpec);
  135.         return LFOSpec->AmplitudeEnvelope;
  136.     }
  137.  
  138.  
  139. /* get the oscillator type for this LFO specifier */
  140. LFOOscTypes                        LFOSpecGetOscillatorType(LFOSpecRec* LFOSpec)
  141.     {
  142.         CheckPtrExistence(LFOSpec);
  143.         return LFOSpec->Oscillator;
  144.     }
  145.  
  146.  
  147. /* change the oscillator type */
  148. void                                    SetLFOSpecOscillatorType(LFOSpecRec* LFOSpec, LFOOscTypes NewType)
  149.     {
  150.         CheckPtrExistence(LFOSpec);
  151.         LFOSpec->Oscillator = NewType;
  152.     }
  153.  
  154.  
  155. /* get the oscillator modulation mode */
  156. LFOModulationTypes        LFOSpecGetModulationMode(LFOSpecRec* LFOSpec)
  157.     {
  158.         CheckPtrExistence(LFOSpec);
  159.         return LFOSpec->ModulationMode;
  160.     }
  161.  
  162.  
  163. /* change the oscillator modulation mode */
  164. void                                    SetLFOSpecModulationMode(LFOSpecRec* LFOSpec,
  165.                                                 LFOModulationTypes NewType)
  166.     {
  167.         CheckPtrExistence(LFOSpec);
  168.         LFOSpec->ModulationMode = NewType;
  169.     }
  170.  
  171.  
  172. /* find out what the adding mode of the LFO is */
  173. LFOAdderMode                    LFOSpecGetAddingMode(LFOSpecRec* LFOSpec)
  174.     {
  175.         CheckPtrExistence(LFOSpec);
  176.         return LFOSpec->AddingMode;
  177.     }
  178.  
  179.  
  180. /* set a new adding mode for the LFO */
  181. void                                    SetLFOSpecAddingMode(LFOSpecRec* LFOSpec,
  182.                                                 LFOAdderMode NewAddingMode)
  183.     {
  184.         CheckPtrExistence(LFOSpec);
  185.         LFOSpec->AddingMode = NewAddingMode;
  186.     }
  187.  
  188.  
  189. /* for wave table lfo oscillators only */
  190. struct EnvelopeRec*        GetLFOSpecWaveTableIndexEnvelope(LFOSpecRec* LFOSpec)
  191.     {
  192.         CheckPtrExistence(LFOSpec);
  193.         return LFOSpec->WaveTableIndexEnvelope;
  194.     }
  195.  
  196.  
  197. /* get the sample selector list */
  198. struct SampleSelectorRec*    GetLFOSpecSampleSelector(LFOSpecRec* LFOSpec)
  199.     {
  200.         CheckPtrExistence(LFOSpec);
  201.         return LFOSpec->SampleSources;
  202.     }
  203.  
  204.  
  205. /* set the extra value */
  206. void                                    SetLFOSpecExtraValue(LFOSpecRec* LFOSpec, double Value)
  207.     {
  208.         CheckPtrExistence(LFOSpec);
  209.         LFOSpec->ExtraValue = Value;
  210.     }
  211.  
  212.  
  213. /* get the extra value */
  214. double                                GetLFOSpecExtraValue(LFOSpecRec* LFOSpec)
  215.     {
  216.         CheckPtrExistence(LFOSpec);
  217.         return LFOSpec->ExtraValue;
  218.     }
  219.